<?php
/**
 * @fileoverview    单品最终页
 * @author          gaojian3
 * @date            2012.02.10
 * @copyright       sina meila
 */

include ('../../__global.php');

class show_goods extends ml_controller
{
    private $rid;
    private $frm;
    public function initParam()
    {
        $this->rid=$this->input('rid','get');
        $this->frm = Tool_string::un_html($this->input('frm','get'));
    }
    public function checkParam()
    {
        if(ml_tool_resid::is_resid($this->rid)==0)
        {
            $this->redirect(ml_tool_urlMaker::error_del($this->rid));//rid错误，未发现宝贝
        }
        $this->init_owner(ml_tool_resid::resid2uid($this->rid));
    }

    public function main()
    {

        //实例化dbContent model
        $oContent=new ml_model_dbContent();
        $rs=$oContent->get_by_rid($this->rid);
        $contentData=$oContent->get_data();
        

        //判断宝贝是否删除
        if(!$rs){
            $this->redirect(ml_tool_urlMaker::error_del($this->rid));
        }
        
        //行为LOG        
        ml_tool_actionlog::view_show_goods($this->__visitor['uid'] , $this->rid , $contentData['gd_catelog'] , $contentData['gd_info']['tags'] , $contentData['gd_price']);
        
        $oid=ml_tool_resid::resid2uid($this->rid);
        //判断删除
        if($contentData['status']==9)
        {
            $this->redirect(ml_tool_urlMaker::error_del($this->rid));    //宝贝已删除
        }
        //判断审核
        //if($contentData['audit_status']==9){
        //    $this->redirect(ml_tool_urlMaker::error_del($this->rid));
        //}

        $content_meta = Tool_string::un_html($contentData['content']);

        $uid = $this->__visitor['uid'];


        //获取用户名片信息
        $obizUser = ml_biz_user_getinfo::get_instance();
        $obizUser->initUser($oid,$uid);
        $data = $obizUser->getUserArea();


        $this->set_scope_var('$rid' , $this->rid);
        $this->set_scope_var('$oid' ,$contentData['uid']);
        $this->set_scope_var('$pid' ,$contentData['pic_id']);
        
        // 你也许喜欢 和 喜欢这个宝贝的mm还在看
        $bizTag = new ml_biz_tag();
        $data['cate_array'] = $bizTag->getyoulike($contentData['gd_info']['tags'],$contentData['rid'],$contentData['gd_catelog']);
        
        //获取品类中文
        $contentData['gd_cate'] = ml_tool_catelog::catelogMaker(ml_tool_catelog::catelogNum($contentData['gd_catelog']));
        //获取价格
        $contentData['gd_price']=ml_tool_standardShow::rmb_price($contentData['gd_price']);

        //数据格式化处理
        $contentData['gd_title']=ml_tool_formatContent::format_content($contentData['gd_title']);
        $contentData['content']=ml_tool_formatContent::format_content($contentData['content']);

        //获取中文电商名
        $contentData['shop_cn']=ml_tool_shop::url2shopcn($contentData['gd_info']['gd_url']);
        $contentData['shop_logo'] =ml_tool_shop::url2shoplogo($contentData['gd_info']['gd_url']);
        

        //通过uid生成用户头像地址
        $contentData['vuid_head_small_url']=ml_tool_picid::uid2portrait($uid);

        //通过uid生成用户头像地址
        $contentData['head_small_url']=ml_tool_picid::pid2url($contentData['uid'],ML_HEADER_PICSIZE_50,ML_PICTYPE_HEADER);
        //通过pid生成商品图片地址
        $contentData['content_pic_url']=ml_tool_picid::pid2url($contentData['pic_id'],'gds');
        
        if( strtotime($contentData['ctime']) > 1340064000 ){  
             $contentData['content_big_pic_url'] =str_ireplace('w320.jpg','or.jpg',$contentData['content_pic_url']);    
        }else{
            $contentData['content_big_pic_url']=$contentData['content_pic_url'];
        }
        
        //是否已表态
        /*
        $oilike=new ml_model_dbILike();
        if(empty($uid)){
            $contentData['ifilike']=false;
        }else{
            $rs=$oilike->isIAttByRid($uid,$this->rid,$result);
            if($rs){
                $contentData['ifilike']=$result;
            }else{
                $contentData['ifilike']=false;
            }
        }
        
        //喜欢Ta的人
        $likeme=new ml_model_dbLikeMe();
        $rs=$likeme->getListByRid($oid,$this->rid,0,8,'',$uidlist);
        $oNick=new ml_model_rdsHash();
        if(is_array($uidlist)){
            foreach($uidlist  as $val){
                $uids[]=$val['act_uid'];
            }
            $oNick=new ml_model_rdsHash();
            $uidArr=ml_tool_nick::uids2nicks($uids);
            $nickArr=array_combine($uids,$uidArr);
            foreach($uidlist  as $val){
                $likeUids[$val['act_uid']]['head']=ml_tool_picid::uid2portrait($val['act_uid']);
                $likeUids[$val['act_uid']]['nick']=$nickArr[$val['act_uid']];
            }
        }else{
            $likeUids=array();
        }
        $data['likeUids']=    $likeUids;
         */
        $rids=array(
        0=>$this->rid
        );
        //各种数  表态数
        $oRedis=new ml_model_rdsCount();
        $oRedis->getAttitudeCount($rids);
        $countAtti=$oRedis->get_data();
        $oRedis->getCommentCount($rids);
        $countComment=$oRedis->get_data();
//        $oRedis->getColCnt($rids);
        $countCol=$oRedis->get_data();

        //$data['countAtti']=$countAtti[$this->rid];
        $data['countComment']=$countComment[$this->rid];
        //$data['countCol']=$countCol[$this->rid];
        $moreshare = $oContent->get_content_by_uid($data['owner_uid'], 0, 12);

        //        $pin_biz=new ml_biz_pinboard($moreshare, $data['owner_uid'], $this->__isself,true,array());
        
        // $pin_biz=new ml_biz_pinboard($moreshare, $data['owner_uid'],
        // $this->__isself,true,array());

        $frm = 'show'.$this->frm ? $this->frm : '';
        if (isset ( $contentData ['gd_info'] ['gd_click_tinyurl'] ) && ! empty ( $contentData ['gd_info'] ['gd_click_tinyurl'] )) {
            $data ['tinyurl'] = ml_tool_urlMaker::tinyurl ( $contentData ['gd_info'] ['gd_click_tinyurl'] ) . '?jout=show&frm='.$frm.'&rid=' . $this->rid;
        } else{
            if (isset ( $contentData ['gd_info'] ['gd_click_url'] ) && ! empty ( $contentData ['gd_info'] ['gd_click_url'] )) {
                $contentData ['gd_info'] ['gd_url'] = $contentData ['gd_info'] ['gd_click_url'];
            }
            //$oTinyurl = new ml_model_mcTinyurl ();
            //$tinyurl = $oTinyurl->longurl2tiny ( $contentData ['gd_info'] ['gd_url'] );
            if ($tinyurl)
                $data ['tinyurl'] = ml_tool_urlMaker::tinyurl ( $tinyurl ) . '?jout=show&frm='.$frm.'&rid=' . $this->rid;
            else
                $data ['longurl'] = '/page/content/goods_redirect.php?url=' . urlencode ( $contentData ['gd_info'] ['gd_url'] );
        }
        
        define('ML_SHOW_GOODS_FRM', 'swgds');
        $pin_biz = new ml_biz_pin_content ();
        $html = $pin_biz->output ( $uid, $moreshare, false );
        

        $data['morehtml'] = ml_tool_pinOutput::groupPinByColumn($html,3);
        $data['is_goods'] = Tool_dataMultiplex::isAttribute(ML_CONTENT_XRANK_GOODS, $contentData['type_xrank']);
        $data['tags'] = array_slice($contentData['gd_info']['tags'], 0 , 3);
        $data=array_merge($data,$contentData);
        
        $this->set_scope_var('$weiboAppKey',OPENAPI_WEIBO_APP_KEY);
        $this->set_scope_var('$skilltags',$data['skill_tags']);
        $this->add_page_description($content_meta." - 美啦用户@".$data['nickname']."分享的宝贝 - ".$data['gd_title']);
        $tags=implode(",", $data['gd_info']['tags']);
        $tags=empty($tags)?ML_META_KEY_PUBLIC:$tags;//容错
        $this->add_page_keyword($tags);
        $data['title']="[图]".$data['gd_title'].' - 美啦';
        $data['visitor'] =$uid;                    //访问者
        $data['noh1'] = true;                   //这个页面h1标签加在商品上
        $this->page_output('content::show_goods',$data);
    }
}
new show_goods();